package com.example.basecon;



import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class MainActivity extends Activity {

	 private Button btnDec, btnBin, btnOct, btnHex; 
	 private EditText edtInput, edtResult; 
	 private Spinner spinner; 


	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

        View.OnClickListener onClick = new View.OnClickListener() { 
        @Override 
        public void onClick(View v) { 
        // TODO Auto-generated method   
        	if (v == btnDec ) { 
        		BaseConvertor base = new BaseConvertor (spinner.getSelectedItem().toString(), "DEC", 
        		edtInput.getText().toString()); 
        		 edtResult.setText(base.getNumber()); 
        		 } 
        	else if (v == btnBin) { 
        		 BaseConvertor base = new BaseConvertor(spinner 
        		 .getSelectedItem().toString(), "BIN", 
        		edtInput 
        		 .getText().toString()); 
        		 edtResult.setText(base.getNumber()); 
        		 if(base.getNumber().equals("data don't only match : [0/1]")){
        			  Toast.makeText(getBaseContext(), "aa",Toast.LENGTH_LONG).show();
        		 }
        		
     		 
        		 } 
        	else if (v == btnOct) { 
        			 BaseConvertor base = new  BaseConvertor(spinner 
        		 .getSelectedItem().toString(),"OCT", 
        		edtInput.getText().toString()); 
        			 edtResult.setText(base.getNumber()); 
        		 } 
        	else if (v == btnHex) { 
        		 BaseConvertor base = new BaseConvertor(spinner 
        		 .getSelectedItem().toString(), "HEX", 
        		edtInput 
        		 .getText().toString()); 
        		 edtResult.setText(base.getNumber()); 
        		 } 
        		 
        
        } 
}; 
        
        btnDec.setOnClickListener(onClick); 
        btnBin.setOnClickListener(onClick); 
        btnOct.setOnClickListener(onClick); 
        btnHex.setOnClickListener(onClick); 


    }
    

	private void setWidgets() { 
   	 btnDec = (Button) findViewById(R.id.btnDec); 
   	 btnBin = (Button) findViewById(R.id.btnBin); 
   	 btnOct = (Button) findViewById(R.id.btnOct); 
   	 btnHex = (Button) findViewById(R.id.btnHex); 
   	 spinner=(Spinner) findViewById(R.id.spBase); 
   	 edtResult = (EditText)findViewById(R.id.edtResult); 
   	 edtInput  = (EditText)findViewById(R.id.edtInput); 
   	 
   	 ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( 
   	 this, R.array.base_string, android.R.layout.simple_spinner_item); 
   	 
   	 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
   	 spinner.setAdapter(adapter); 
   	 } 



	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
